﻿using FluentValidation;
using PMS.Core.Configuration.CommonEnumConfigs;
using PMS.Data.Entities.Settings;
using PMS.Web.Framework.Validators;
using PMS.Web.Models.Customers;

namespace PMS.Web.Validators.Customer
{
    public partial class RegisterValidator : BaseModelValidator<RegisterModel>
    {
        public RegisterValidator(CustomerSettings customerSettings)
        {
            if(customerSettings.UserRegistrationType != UserRegistrationType.MobileOnly)
            {
                RuleFor(x => x.Email).NotEmpty().WithMessage(ValidatorRuleString.EmailRequired);
                RuleFor(x => x.Email).EmailAddress().WithMessage(ValidatorRuleString.Validators_Email);
                RuleFor(x => x.Loginname).IsUsername(customerSettings).WithMessage(customerSettings.UsernameValidationTips);
            }

            RuleFor(x => x.Mobile).IsMobileNumber(customerSettings).WithMessage(ValidatorRuleString.Validators_MobilePhone);

            //Password rule
            RuleFor(x => x.Password).IsPassword(customerSettings);
            RuleFor(x => x.ConfirmPassword).NotEmpty().WithMessage(ValidatorRuleString.Validation_PasswordNotEmpty);
            RuleFor(x => x.ConfirmPassword).Equal(x => x.Password).WithMessage(ValidatorRuleString.Validation_ConfirmPasswordNotMatch);

        }
    }
}
